Partial Class Admin_Providers
  Inherits System.Web.UI.Page

    Private Sub SecurePage()
        Dim sec As New Secure

        sec.ParentPage = Me
        sec.AddDataGridColumn(Me.DataGrid, DataGrid.Columns.Count - 3, Secure.ControlTypes.DeleteType)
        sec.AddDataGridColumn(Me.DataGrid, DataGrid.Columns.Count - 4, Secure.ControlTypes.EditType)
        sec.SetPageAccess(Session("UserName"))
        sec = Nothing

    End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If brokers_cmb.Items.Count < 1 Then

            Dim zClass As New LookUp.General_Lookup
            brokers_cmb.Items.Clear()
            zClass.Loader(brokers_cmb, "BROKER", "broker_desc", "broker_cd")
            zClass.LookUpCode = "PROVIDER"
            brokers_cmb.Items.Insert(0, "")

            Back_Panel.Visible = True
            Search_Panel.Visible = True
            DataGrid.CurrentPageIndex = 0
            If IsNothing(Session("broker_cd")) Then
                Back_Panel.Visible = False
                zClass.DataGridFill(DataGrid, Results_lbl, Session("broker_cd"))
            Else
                brokers_cmb.SelectedValue = Session("broker_cd")
                Search_Panel.Enabled = False
                zClass.DataGridFill(DataGrid, Results_lbl)
            End If

        End If

        Dim Edit_Image As Image = CType(Me.Master.FindControl("A2"), Image)
        Edit_Image.ImageUrl = "~/images/redT.PNG"
        Dim Edit_Button As LinkButton = CType(Me.Master.FindControl("Providers_btn"), LinkButton)
        Edit_Button.ForeColor = Drawing.Color.Black
        Dim Edit_Panel As Panel = CType(Me.Master.FindControl("Affiliates_Panel"), Panel)
        Edit_Panel.Visible = True
        'Dim Edit_Menu As Button = CType(Me.Master.FindControl("Affiliates_btn"), Button)
        'Edit_Menu.Enabled = False
        SecurePage()
  End Sub

  Protected Sub brokers_cmb_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles brokers_cmb.SelectedIndexChanged
        If brokers_cmb.SelectedItem.Text = "" Then Exit Sub

    Dim zClass As New LookUp.General_Lookup
    zClass.LookUpCode = "PROVIDER"
    DataGrid.CurrentPageIndex = 0
    zClass.DataGridFill(DataGrid, Results_lbl, brokers_cmb.SelectedValue)

  End Sub

  Protected Sub Back_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Back_btn.Click
    Session.Remove("broker_cd")
    Response.Redirect("~/Admin/Brokers.aspx")
  End Sub

  Protected Sub DataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.ItemCommand
    If e.CommandName = "Edit" Or e.CommandName = "View" Then
      Session("provider_cd") = e.Item.Cells(0).Text
      Session("provider_mode") = e.CommandName
      Response.Redirect("~/Admin/Add_Providers.aspx")

    ElseIf e.CommandName = "Delete" Then
      Dim zClass As New LookUp.General_Lookup
      zClass.LookUpCode = "PROVIDER"

      If zClass.OKtoDELETE(e.Item.Cells(0).Text) = True Then
        zClass.ExecQuery("DELETE FROM provider_mstr WHERE provider_cd='" & e.Item.Cells(0).Text & "'")

        DataGrid.CurrentPageIndex = 0
        If Session("broker_cd") <> Nothing Then
          zClass.DataGridFill(DataGrid, Results_lbl, Session("broker_cd"))
                ElseIf brokers_cmb.SelectedItem.Text <> "" Then
                    zClass.DataGridFill(DataGrid, Results_lbl, brokers_cmb.SelectedValue)
                Else
                    zClass.DataGridFill(DataGrid, Results_lbl)
                End If

            End If

        ElseIf e.CommandName = "Products" Then
            Session("provider_cd") = e.Item.Cells(0).Text
            Session("broker_cd") = e.Item.Cells(7).Text
            Response.Redirect("~/Admin/Products.aspx")

        End If
    End Sub

    Protected Sub Add_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add_btn.Click
        Session("provider_mode") = "Add"
        Response.Redirect("~/Admin/Add_Providers.aspx")
    End Sub

    Protected Sub DataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
        DataGrid.CurrentPageIndex = e.NewPageIndex
        Dim zClass As New LookUp.General_Lookup

        If Session("broker_cd") <> Nothing Then
            zClass.DataGridFill(DataGrid, Results_lbl, Session("broker_cd"))
        ElseIf brokers_cmb.SelectedItem.Text <> "" Then
            zClass.DataGridFill(DataGrid, Results_lbl, brokers_cmb.SelectedValue)
        Else
            zClass.DataGridFill(DataGrid, Results_lbl)
        End If

    End Sub
End Class